package leetcode.editor.cn.q1_300.q;

/**
 * @author qidi
 * @date 2021-11-03 11:14:43
 */
class Q0027_RemoveElement {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int removeElement(int[] nums, int val) {
            int i = 0;
            int len = nums.length;
            while (i < len) {
                if (nums[i] == val) {
                    nums[i] = nums[len - 1];
                    len--;
                } else {
                    i++;
                }
            }

            return len;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0027_RemoveElement().new Solution();
        System.out.println(solution.removeElement(new int[]{0, 1, 2, 2, 3, 0, 4, 2}, 2));
    }
}